package com.lwj.liwanjia.utils;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;

/**
 * Created by Administrator on 2017/12/18.
 */

public class EditHuifuDialog extends Dialog {

    private EditText editPinLun;
    private SendHuifu sendHuifu;
    private Context context;

    public void setSendPinlun(SendHuifu sendHuifu) {
        this.sendHuifu = sendHuifu;
    }

    public EditHuifuDialog(@NonNull Context context) {
        super(context, R.style.MyDialog);
        setContentView(R.layout.edit_dialog);
        initView();
        this.context = context;
    }

    private void initView() {
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.dialog_animation);
        setCanceledOnTouchOutside(true);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = params.MATCH_PARENT;
        params.height = params.WRAP_CONTENT;
        window.setAttributes(params);
        editPinLun = (EditText) findViewById(R.id.edit_pinglun);
        TextView tvSend = (TextView) findViewById(R.id.tv_send);
        tvSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String strHuifu = editPinLun.getText().toString();
                if (!TextUtils.isEmpty(strHuifu)) {
                    sendHuifu.send(strHuifu);
                } else {
                    Toast.makeText(context, "回复不能为空", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    public EditText getEditPinLun() {
        return editPinLun;
    }

    public interface SendHuifu {
        void send(String huiFu);
    }
}
